<template>
	<view class="login-box">
		<view class="logo-box">
			<image src="@/static/logo.png" mode="widthFix" class="logo"></image>
		</view>
		<view class="input-group">
			<view class="flex flex-middle b-b">
				<view class="flex-item">
					<input type="text" value="" placeholder="账号" v-model="user"/>	
				</view>
			</view>
			<view class="flex flex-middle b-b">
				<view class="flex-item">
					<input type="text" value="" placeholder="密码" password v-model="pwd"/>	
				</view>
			</view>	
		</view>
		<button type="primary" @click="login" hover-class="none">登 录</button>
		<view class="flex flex-right">
			<view class="uni-link" @click="forgetPassword">忘记密码</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				user:'',
				pwd:'',
				account:[{
					user:'wuge',
					pwd:'1234qwer'
				},{
					user:'admin',
					pwd:'12341234'
				}]
			}
		},
		methods: {
			login(){
				console.log(this.user,this.pwd)
				this.verify(()=>{
					this.request()
				})
			},
			verify(callback){
				if(this.user.length < 2) return uni.showToast({
					icon:'none',
					title: '用户名不得小于2位'
				})
				if(this.pwd.length < 8) return uni.showToast({
					icon:'none',
					title: '密码不能小于8位'
				})
				
				// var authed = this.account.some((item)=>{
				// 	return this.user == item.user && this.pwd == item.pwd
				// })
				
				// if(!authed) return uni.showToast({
				// 	icon:'none',
				// 	title: '用户名或密码错误'
				// })
				
				callback && callback()
				
			},
			request(){
				this.$$.request({
					url:this.config.login,
					method:"POST",
					data:{
						username:this.user,
						password:this.pwd
					}
				},true).then((res)=>{
					console.log(res)
					this.$store.dispatch('getLogged',true)
					this.$store.dispatch('getUser',this.user)
					
					this.$$.setStorage("userinfo",this.user,1)
					
					uni.switchTab({
						url:"../index/index"
					})
				}).catch(()=>{					
					console.log("请求失败")
				}).finally(()=>{
					console.log("complate")
				})
			},
			forgetPassword(){
				uni.showModal({
					title: '提示',
					content: '请联系管理员重置密码',
					showCancel: false,
					cancelText: '',
					confirmText: '知道了',
					success: res => {},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style lang="scss" scoped>
page {
	background-color: $uni-bg-color;
}
.login-box {
	padding: 225upx $uni-spacing-row-lg;
}
.logo-box {
	margin-bottom: 105upx;
	text-align: center;
	font-size: 36upx;
	color: $uni-text-color;
	.logo {
		display: block;
		width: 144upx;
		margin: 0 auto 30upx;
	}
}
.input-group {
	.flex {
		height: 82upx;
		margin-bottom: 47upx;
		.label {
			margin-right: $uni-spacing-row-lg;
			font-size: 32upx;
			color: $uni-text-color-grey;
		}
		&:last-child {
			margin-bottom: 73upx;
		}
	}
}
uni-button {
	margin-top: 73upx;
	margin-bottom: 40upx;
}
.flex-right {
	flex-direction: row-reverse
}
.uni-link {
	padding: 0 30upx;
	font-size: 28upx;
	color: $uni-text-color-grey;
}
</style>
